// components/address-item/index.js
import {AddressModel} from '../../model/address'
var address = new AddressModel()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    model:Object
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    defaultAction(){
      address.save({id:this.properties.model.id,isDefault:this.properties.model.isDefault==1?0:1}).then(
        res=>{
          if(res.code===0){
            this.triggerEvent("upData")
          }
        }
      )
    },
    editAction(){
      wx.navigateTo({
        url: '/pages/address/detail/detail?id='+ this.properties.model.id,
      })
    },
    deleteAction(){
      wx.showModal({
        content: '是否删除该地址',
        confirmText: '删除',
        confirmColor: '#F7859C',
        success: res=>{
          if (res.confirm) {
            address.del(this.properties.model.id).then(
              res=>{
                if(res.code===0){
                  this.triggerEvent("upData")
                }
              }
            )
          }
        }
      })
      
    }
  }
})
